/**
 * Created by Administrator on 2025/5/28.
 * */
#include "AICFARTrainController.h"
#include <iostream>
#include <thread>

BaseObject *createAICFARTrainController() {
    return new AICFARTrainController();
}

void destroyAICFARTrainController(BaseObject *p) {
    SAFE_DELETE(p);
}

AICFARTrainController::AICFARTrainController(){
}

AICFARTrainController::~AICFARTrainController() {
}

/* 如果使用了DDS_Reader或者DDS_Writer，则对应的input或者output前64个字节为DataFormat head首部 */
void AICFARTrainController::onCompute(buffer_table_t *input, buffer_table_t *output) {
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    if (input->list[1]->valid) {
        int *pState = reinterpret_cast<int*>(input->list[1]->data);
        if (*pState > 0) {
            auto aiCFARNetStateHolder = GlobalParameters::shareInstance()->findParameter("aiCFARNetState");
            int *aiCFARNetState = static_cast<int*>(GlobalParameters::shareInstance()->getValue(aiCFARNetStateHolder, dynamic_cast<TaskModule*>(this)));
            *aiCFARNetState = *pState;
            std::cout << "AICFARTrainController::onCompute 接收到状态更新：state=" << *pState << "; !!!!!!!!!!" << std::endl;
        }
    }
}
